package model;


import entity.Cell;
import java.util.Vector;
import observer.ArenaObserver;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author minhtue001
 */
public class Arena {
    private static final Arena arena = new Arena();
    public final int WIDTH = 20;
    public final int HEIGHT = 15;
    private Vector<Cell> emptyCells;
    private Vector<Cell> obstacleCells;
    
    public boolean isObstacle(Cell c) {
        for (Cell item: obstacleCells) 
            if (item.isEqual(c)) return true;
        return false;
    }
    private Arena() {
        emptyCells = new Vector<Cell>();
        obstacleCells = new Vector<Cell>();
    }
    
    public static Arena getInstance() {
        return arena;
    }

    public Vector<Cell> getEmptyCells() {
        return emptyCells;
    }

    public void setEmptyCells(Vector<Cell> emptyCells) {
        this.emptyCells = emptyCells;
        
    }

    public Vector<Cell> getObstacleCells() {
        return obstacleCells;
    }

    public void setObstacleCells(Vector<Cell> obstacleCells) {
        this.obstacleCells = obstacleCells;
    }   
    
    public boolean isEmptyCell(Cell cell) {
        boolean found = false;
        for (Cell c : emptyCells) {
            if (c.x == cell.x && c.y == cell.y)
                found= true;
        }
        return found;
    }
    
    public boolean isObstacleCell(Cell cell) {
        boolean found = false;
        for (Cell c : obstacleCells) {
            if (c.x == cell. x && c.y == cell.y)
                found = true;
        }
        return found;
    }
    
    public void addEmptyCell(Cell cell) {
        if (!insideArena(cell))
            return;
        if (isEmptyCell(cell))
            return;
        emptyCells.add(cell);
        ArenaObserver.getInstance().noticeView();
    }
    
    public void addObstacleCell(Cell cell) {
        if (!insideArena(cell))
            return;
        if (isObstacleCell(cell))
            return;
        if (isEmptyCell(cell))
            return;
        obstacleCells.add(cell);
        ArenaObserver.getInstance().noticeView();
    }
    
    public boolean insideArena(Cell cell) {
        return 0 <= cell.x && cell.x < WIDTH && 0 <= cell.y && cell.y < HEIGHT;
    }
}
